<?php
/**
 * LoginController Created by Geoff
 * @author GeoffreyEmbuscado 02.11.2015
 */
class LoginController extends BaseController {
	// CRUD 
	public $crud = false;
	
	// Table
	public $table = 'user';

	// Eloquent Model
	public $model = 'user';

	// Base - Route Name
	public $base = 'login';

	// Localization
	public $local = 'en';

	// Language File Name
	public $language = 'login';

	// Breadcrumbs
	public $breadcrumbs = [ ['link' => 'login' , 'title' => 'Login'] ];
	
	/*
	 * Shows Login Form
	 * @author GeoffreyEmbuscado
	 * Description: Display of Login Form
	 */
	public function loginForm() {
		if( Auth::check() ){
			return Redirect::to('dashboard');
		}
		return View::make('layout.login');
	}

	/**
	 * POST login
	 * @author GeoffreyEmbuscado
	 * Description: Submition of login
	 */
	public function loginSubmit() {
		if( Auth::attempt(array('username' => Input::get('username'), 'password' => Input::get('password'))) ) {
			return Redirect::to('dashboard');
		} 
		
		Session::flash('login-error', Lang::get('login.warning'));
		return Redirect::to('login');
	}
	
	/**
	 * GET logout
	 * @author GeoffreyEmbuscado
	 * Description: Logout of user
	 */
	public function logout() {
		Auth::logout();
		return Redirect::to('login');
	}

}